package asteroids.model.programs.parsing.expressions;

import java.util.Map;

import asteroids.model.Ship;
import asteroids.model.SpaceObject;
import asteroids.model.programs.parsing.types.DoubleLiteral;
import asteroids.model.programs.parsing.types.EntityLiteral;
import asteroids.model.programs.parsing.types.Type;

/**
 * A class of get y-coordinate expressions.
 * A get y-coordinate expression returns the y-coordinate of the position vector of an entity.
 * 
 * @author Thijs Dieltjens - Wim Konings
 * @version 2.0
 */
public class GetYExpr extends EntityExpr {

	public GetYExpr(Expression e,int line, int column) {
		super(e, line, column);
	}

	@Override
	public Type eval(Ship ship, Map<String, Type> globals) {
		Type type = getOperand().eval(ship, null);

		if(type instanceof EntityLiteral && ((EntityLiteral) type).getValue() !=null){
			SpaceObject spaceObject = ((EntityLiteral) type).getValue();
			return new DoubleLiteral(spaceObject.getCoordinates().getYCoordinate());
		}
		return new DoubleLiteral();
	}
}
